/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.ext.DialectSyntaxParser;
import net.iwsh.core.db.ext.SQLWithParams;
import net.iwsh.core.utils.IDGenerator;

import com.us.usws.model.domain.system.Clz;
import com.us.usws.model.flat.system.DOClz;
import com.us.usws.support.uitls.DataPageUtil;

/**
 * DAO class
 * @author robot
 */
public class ClzDAO extends BasePageSearchDAO<Clz>{

	/**
	 * Query SQLs
	 */
	private static final String SQL_GET_TOTAL_COUNT = "select count(*) from sys_clz";

	private static final String SQL_GET_ALL_CLZS = "select * from sys_clz";

	private static final String SQL_GET_CLZ_BY_PK = "select * from sys_clz where uid = ?";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_CLZ = "insert into sys_clz(uid,school_uid,clz_grade_code,clz_sn,create_by_uid,create_date,last_upd_by_uid,last_upd_date) values (?,?,?,?,?,?,?,?)";

	private static final String SQL_UPDATE_CLZ = "update sys_clz set school_uid=?, clz_grade_code=?, clz_sn=?, last_upd_by_uid=?, last_upd_date=? where uid=?";

	private static final String SQL_DEL_CLZ = "delete from sys_clz where uid=?";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get Count.
	 */
	public int getTotalCount() {
		return dbe.getCount(SQL_GET_TOTAL_COUNT);
	}

	/**
	 * Get all list.
	 */
	public List<Clz> getAllClzs() {
		return dbe.list(SQL_GET_ALL_CLZS, Clz.class);
	}

	/**
	 * Get all list by pagination.
	 */
	public List<Clz> getClzs(int start, int end) {
		SQLWithParams swp = DialectSyntaxParser.getParser().getPaginationSQLWithParams(SQL_GET_ALL_CLZS, null, start, end);
		return dbe.list(swp.getSql(), Clz.class, swp.getParams());
	}

	/**
	 * Get Clz by primary key.
	 */
	public Clz getClz(String uid) {
		Clz c = dbe.load(SQL_GET_CLZ_BY_PK, Clz.class, uid);
		return c;
	}

	/**
	 * Insert one row.
	 */
	public String insertClz(DOClz clz) {
		String uid = IDGenerator.getInstance().genUID();
		clz.setUid(uid);
		dbe.execute(SQL_INSERT_CLZ, clz.getUid(), clz.getSchoolUid(), clz.getClzGradeCode(), clz.getClzSn(), clz.getCreateByUid(),
				clz.getCreateDate(), clz.getLastUpdByUid(), clz.getLastUpdDate());
		return uid;
	}

	/**
	 * Update by PK.
	 */
	public void updateClz(DOClz clz) {
		dbe.execute(SQL_UPDATE_CLZ, clz.getSchoolUid(), clz.getClzGradeCode(), clz.getClzSn(),
				clz.getLastUpdByUid(), clz.getLastUpdDate(), clz.getUid());
	}

	/**
	 * Delete row by PK.
	 */
	public void deleteClz(String uid) {
		dbe.execute(SQL_DEL_CLZ, uid);
	}

	public void loadSchoolsByPage(DataPageUtil<Clz> dataPageUtil) {
		String countSql = "select count(*) from sys_clz where 1=1";
		String sql = " select * from sys_clz where 1=1";
		SQLWithParams swp = initSQLWithParams(dataPageUtil, null, countSql, sql);
		dataPageUtil.setResult(dbe.list(swp.getSql(), Clz.class, swp.getParams()));
	}

}